package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryCalculateRuleGroupAddDTO;
import org.jsola.hr.dto.SalaryCalculateRuleGroupUpdateDTO;
import org.jsola.hr.entity.SalaryCalculateRuleGroupDO;
import org.jsola.hr.query.SalaryCalculateRuleGroupQuery;
import org.jsola.hr.service.ISalaryCalculateRuleGroupService;
import org.jsola.hr.vo.SalaryCalculateRuleGroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 工价计算规则组
 *
 * @author zhr
 */
@Component
public class SalaryCalculateRuleGroupTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISalaryCalculateRuleGroupService salaryCalculateRuleGroupService;

    /**
     * 生成add测试数据
     * @return SalaryCalculateRuleGroupAddDTO
     */
    public SalaryCalculateRuleGroupAddDTO getSalaryCalculateRuleGroupAddDTO(){
        SalaryCalculateRuleGroupAddDTO salaryCalculateRuleGroupAddDTO = new SalaryCalculateRuleGroupAddDTO();
        salaryCalculateRuleGroupAddDTO.setRuleType(SafeKit.getInteger(getRandomValue("int",4)));
        salaryCalculateRuleGroupAddDTO.setName(getRandomValue("varchar",50));
        salaryCalculateRuleGroupAddDTO.setCompanyId(getRandomValue("varchar",32));
        salaryCalculateRuleGroupAddDTO.setSource(getRandomValue("varchar",32));
        return salaryCalculateRuleGroupAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryCalculateRuleGroupUpdateDTO
     */
    public SalaryCalculateRuleGroupUpdateDTO getSalaryCalculateRuleGroupUpdateDTO(SalaryCalculateRuleGroupVO salaryCalculateRuleGroupVO){
        return salaryCalculateRuleGroupService.selectDOById(salaryCalculateRuleGroupVO.getId(), SITE_ID).to(SalaryCalculateRuleGroupUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryCalculateRuleGroupQuery
     */
    public SalaryCalculateRuleGroupQuery getSalaryCalculateRuleGroupQuery() {
        SalaryCalculateRuleGroupQuery salaryCalculateRuleGroupQuery = new SalaryCalculateRuleGroupQuery();
        List<SalaryCalculateRuleGroupDO> salaryCalculateRuleGroupDOList = salaryCalculateRuleGroupService.list(new SalaryCalculateRuleGroupDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryCalculateRuleGroupDOList)) {
            SalaryCalculateRuleGroupDO salaryCalculateRuleGroupDO = salaryCalculateRuleGroupDOList.get(0);
            salaryCalculateRuleGroupQuery = salaryCalculateRuleGroupDO.to(SalaryCalculateRuleGroupQuery.class);
        }
        return salaryCalculateRuleGroupQuery;
    }

    /**
     * 保存示例
     * @return SalaryCalculateRuleGroupVO
     */
    public SalaryCalculateRuleGroupVO saveSalaryCalculateRuleGroupExample(){
        SalaryCalculateRuleGroupAddDTO addDTO = this.getSalaryCalculateRuleGroupAddDTO();
        SalaryCalculateRuleGroupVO salaryCalculateRuleGroupVO = salaryCalculateRuleGroupService.save(addDTO,buildTokenUser());
        return salaryCalculateRuleGroupVO;
    }


}

